#include "server.h"

namespace server{

HttpServer* HttpServer::instance = nullptr;

server::HttpServer *server::HttpServer::getInstance()
{
    if(instance == nullptr)
    {
        instance = new HttpServer();
    }
    return instance;
}

bool HttpServer::init()
{
    // 返回值是int，表示成功绑定的端口号
    // 这里的listen里面会进行绑定
    int ret = httpServer.listen(QHostAddress::Any,8080);
    if(ret != 8080)
    {
        LOG_ERROR << "绑定失败" << ret;
        return false;
    }

    // 路由配置，这里和ip里的路由不是一个概念，不要搞错
    httpServer.route("/ping",[](const QHttpServerRequest& req){
        (void) req;
        LOG_DEBUG << "[http] 收到 ping 请求";
        return "ping";
    });

    return true;
}

} // end server

